#ifndef SDBADCHUNK_H
#define SDBADCHUNK_H

#include <vector>
#include <math.h>
#include "../src/chipmunk.h"
#include "sdTimed.h"

//Chunks that spawn from dead bad guys
class sdBadChunk : public sdTimed {
public:
	//Creates a bad chunk with the given time to live and body
    inline sdBadChunk(cpFloat ttl, cpBody* body) : sdTimed(ttl, body) {}
	
	//Gets the chunks that spawn when this chunk dies
    void getChunks(std::set<sdTimed*>* chunks) {
        int count = 50; //10 chunks
        cpFloat div = 2 * 3.14159 / count; //each chunk is separated by this angle
        cpFloat iDiv;
    
        for(int i = 0; i < count; i++) {
            cpBody* body = new cpBody(); //Initialize a chunk
            iDiv = i * div;
            sdTimed* bullet = new sdTimed(0.1, body);
            bullet->start();
            bullet->setMass(0.01);
        	bullet->setPos(cpv(body_->p.x + 2 * sin(iDiv), body_->p.y + 2 * cos(iDiv)));
        	bullet->addCircleShape(0, 1, cpvzero, 7);

        	bullet->setVel(cpv(1000 * sin(iDiv), 1000 * cos(iDiv)));
     	
        	chunks->insert(bullet); //Then put it into the set
        }
    }
};

#endif
